package hbase.HbaseStudy;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Hb04_insertDataMore {
    private static String tableName = "sccc01:t3";
    // 添加数据不需要Admin
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        Connection HConn = ConnectionFactory.createConnection(conf);
        Table table = HConn.getTable(TableName.valueOf(tableName));

        // 创建Put列表存放多条数据
        List<Put> puts = new ArrayList<>();

        // 插入数据 shell => put “表名”，“行建”，“列柱：列名”，“值”
        Put put1 = new Put("03".getBytes()); // put “表名”，“行建”
        put1.addColumn("info".getBytes(),"name".getBytes(),"Ket".getBytes());

        Put put2 = new Put("03".getBytes()); // put “表名”，“行建”
        put2.addColumn("info".getBytes(),"sex".getBytes(),"Woman".getBytes());

        Put put3 = new Put("03".getBytes()); // put “表名”，“行建”
        put3.addColumn("info".getBytes(),"age".getBytes(),"23".getBytes());

        Put put4 = new Put("04".getBytes()); // put “表名”，“行建”
        put4.addColumn("info".getBytes(),"name".getBytes(),"Qt".getBytes());

        Put put5 = new Put("04".getBytes()); // put “表名”，“行建”
        put5.addColumn("info".getBytes(),"age".getBytes(),"32".getBytes());

        puts.add(put1);
        puts.add(put2);
        puts.add(put3);
        puts.add(put4);
        puts.add(put5);

        // 提交列表集合数据
        table.put(puts);


        // 释放资源
        table.close();
        HConn.close();

        System.out.println("ok-----------------");
    }
}
